﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace ZYing.QPanel.Converters
{
    public class DateTime2StringConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                if (parameter != null) return parameter;
                return string.Empty;
            }
            switch (value)
            {
                case DateTime dateTime:
                    return dateTime.ToLocalTime().ToString("yyyy/MM/dd HH:mm:ss");
                case DateTimeOffset dateTimeOffset:
                    return dateTimeOffset.ToLocalTime().ToString("yyyy/MM/dd HH:mm:ss");
                case TimeSpan timeSpan:
                    if (timeSpan.TotalDays < 1) return timeSpan.ToString("hh\\:mm\\:ss");
                    break;
            }
            return value.ToString();
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
